import Koa from 'koa';
import path from 'path';
import Static from 'koa-static'
import Cors from 'koa2-cors'
import koaBody from 'koa-body'
import router from './router'
import {corsHandler} from './middleware/cors'
const app=new Koa()

app.use(Cors(corsHandler));
//处理静态资源
app.use(Static(path.resolve(__dirname,"../public")))
app.use(koaBody({
  multipart:true,
  formidable:{
    uploadDir:path.resolve(__dirname,"../public/temp"),
    keepExtensions:true,
    maxFieldsSize:2 * 1024 * 1024
  }
}));
app.use(router.routes()).use(router.allowedMethods());
const PORT=4000
app.listen(PORT,()=>{
  console.log('4000已启动');
  
})